package spikes

import (
	"enjoy-shop/api/base"
	"enjoy-shop/formdata"
	"enjoy-shop/server/spikes"
	"github.com/gin-gonic/gin"
)

// 创建秒杀活动
func CreateSpikesActivity(c *gin.Context) {
	var data formdata.CreateSpikesActivity
	if err := c.ShouldBindJSON(&data); err != nil {
		base.RespData(c, nil, err)
		return
	}
	activity, err := spikes.CreateSpikesActivity(data)
	//判断返回结果
	base.RespData(c, activity, err)
}

// 获取秒杀活动列表
func GetSpikesActivityList(c *gin.Context) {
	list, err := spikes.GetSpikesActivityList()
	base.RespData(c, list.GetSpikesActivityList(), err) //返回结果
}

func GetSpikesGoodsInfo(c *gin.Context) {
	var data formdata.GetSpikesGoodsInfo
	if err := c.ShouldBindJSON(&data); err != nil {
		base.RespData(c, nil, err)
		return
	}
	info, err := spikes.GetGoodsInfo(data)
	base.RespData(c, info, err)
}

// 获取秒杀商品列表
func GetSpikesGoodsList(c *gin.Context) {
	var data formdata.GetSpikesGoodsList
	if err := c.ShouldBindJSON(&data); err != nil {
		base.RespData(c, nil, err)
		return
	}

	list, err := spikes.GetSpikesGoodsList(data)
	base.RespData(c, list, err) //返回结果
}

// 创建秒杀商品sku关联活动方法
func CreateSpikesGoodsSku(c *gin.Context) {
	var data formdata.CreateSpikesGoodsSku
	if err := c.ShouldBindJSON(&data); err != nil {
		base.RespData(c, nil, err)
		return
	}
	activity, err := spikes.CreateSpikesGoodsSku(data)
	//判断返回结果
	base.RespData(c, activity, err)
}
